<?
$g4_path = ".";
include_once("$g4_path/_common.php");
$g4[title] = "이미지보기";
include_once("$g4[path]/head.sub.php");
include_once("$g4[path]/lib/latest.lib.php");
include_once("$g4[path]/lib/outlogin.lib.php");
include_once("$g4[path]/lib/poll.lib.php");
include_once("$g4[path]/lib/visit.lib.php");
include_once("$g4[path]/lib/connect.lib.php");
include_once("$g4[path]/lib/popular.lib.php");
?>

<SCRIPT LANGUAGE='JavaScript'>
// 이미지뷰어
<!-- 
    var win= null;
    function View_Open(img, w, h)
    {
        var winl = (screen.width-w)/2;
        var wint = (screen.height-h)/3;
        var settings  ='height='+h+',';
            settings +='width='+w+',';
            settings +='top='+wint+',';
            settings +='left='+winl+',';
            settings +='scrollbars=yes,';
            settings +='resizable=yes,';
            settings +='status=no';

        win=window.open("","newWindow",settings);
        win.document.open(); 
        win.document.write ("<html><head><title>원본 이미지 보기</title></head>"); 
        win.document.write ("<script>function init(){window.resizeBy(document.all.pop_img.width-document.body.clientWidth, document.all.pop_img.height-document.body.clientHeight+10);}</script>"); 
        win.document.write ("<body bgcolor=white topmargin=0 leftmargin=0 marginwidth=0 marginheight=0 onload='init();'>");
        win.document.write ("<img src='"+img+"' border=0 onclick='window.close();' style='cursor:hand' title='클릭하면 닫혀요' id='pop_img'>");
        win.document.write ("</body></html>");
        win.document.close();
    }
//-->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
<!-- 
image_directory = "";   //배경이미지 경로
clear = new Image();  clear.src = image_directory + "./img/blank.gif";
<?
//파일 뽑기
$sql2 = " select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no limit 0, 8 "; 
$result2 = sql_query($sql2);
for ($j=0; $row2 = sql_fetch_array($result2); $j++) {
$view_one = "{$g4['path']}/data/file/{$bo_table}/{$row2['bf_file']}";
?>
view_img<?=$j?> = new Image();
view_img<?=$j?>.src = "<?=$g4['path']?>/data/file/<?=$bo_table?>/<?=$row2['bf_file']?>";
<? } ?>
function bgChange(imgName) { 
	document.all.view_img.src = eval(imgName + ".src");
}
//  -->
</SCRIPT>

<table cellspacing="0" cellpadding="0" border="0" align="center">
	<tr>
		<td colspan="8" style="padding:10 0 10 0px;" align="center" valign="top"><div style='width:570px; height:450px; position:relative; overflow:hidden;' align=center><img src="<?=$view_one?>" name="view_img" height="457" border="0"></a></div></td>
	</tr>
	<tr>
<?
//파일 뽑기
$sql = " select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no limit 0, 8 "; 
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++) {

//썸네일 코드 시작
$data_path = $g4['path'] . "/data/file/{$bo_table}";//라이브러리 파일 참조
$thumb_path = $data_path . '/thumbOpen';

$view_w = 60; //썸네일 가로사이즈
$view_h = 75; //썸네일 세로사이즈
$sch_q = 100; //썸네일 퀼리티

if (!is_dir($thumb_path)) {
@mkdir($thumb_path, 0707);
@chmod($thumb_path, 0707);
}
    $filename = $row[bf_file]; //파일명
    $thumb = $thumb_path.'/'.$filename; //썸네일
    if (!file_exists($thumb))
    {
	$file = $data_path.'/'.$filename; //원본
        if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file))
        {
            $size = getimagesize($file);
            if ($size[2] == 1)
                $src = imagecreatefromgif($file);
            else if ($size[2] == 2)
                $src = imagecreatefromjpeg($file);
            else if ($size[2] == 3)
                $src = imagecreatefrompng($file);
            else
                continue;

            $rate = $view_w / $size[0];
            $height = (int)($size[1] * $rate);

            if ($height < $view_h)
                $dst = imagecreatetruecolor($view_w, $height);
            else
                $dst = imagecreatetruecolor($view_w, $view_h);
            imagecopyresampled($dst, $src, 0, 0, 0, 0, $view_w, $height, $size[0], $size[1]);
            imagejpeg($dst, $thumb_path.'/'.$filename, $sch_q);
            chmod($thumb_path.'/'.$filename, 0707);
        }
    }

	if (file_exists($thumb) && $filename) {
?>
	<td bgcolor="#f1f1f1" style="padding:10 0 10 0px;" align="center" valign="top"><a href="javascript:void(0);" onClick="View_Open('<?=$data_path?>/<?=$filename?>')" onMouseOver="bgChange('view_img<?=$i?>');" onMouseOut="bgChange('view_img<?=$i?>');"><img src='<?=$thumb?>' border=0></a></td></td>
<? } } ?></td>
	</tr>
</table>

<?
include_once("$g4[path]/tail.sub.php");
?>